package com.n9.qq.android.login.tlv;

import com.n9.qq.util.Util;

import java.util.Objects;

/**
 * @author ice
 * @since 2019/2/12 14:44
 */
public class Tlv0124 extends BaseTlv {

    int len;

    public Tlv0124() {
        this.cmd = 0x0124;
    }

    /**
     * @param osType        系统类型
     * @param osVersion     系统版本
     * @param netWorkType   上网方式
     * @param simName       运营商名称
     * @param var5          final new byte[0]
     * @param apnName       网络接入名称
     * @return
     */
    public byte[] getData(byte[] osType, byte[] osVersion, int netWorkType, byte[] simName, byte[] var5, byte[] apnName) {
        if (Objects.isNull(osType)) {
            osType = new byte[0];
        }
        if (Objects.isNull(osVersion)) {
            osVersion = new byte[0];
        }
        if (Objects.isNull(simName)) {
            simName = new byte[0];
        }
        if (Objects.isNull(var5)) {
            var5 = new byte[0];
        }
        if (Objects.isNull(apnName)) {
            apnName = new byte[0];
        }

        this.len = 2 + osType.length + 2 + osVersion.length + 2 + 2 + simName.length + 2 + var5.length + 2 + apnName.length;
        byte[] data = new byte[this.len];
        int index = 0;

        int osTypeLen = osType.length;
        Util.int16_to_buf(data, index, osTypeLen);
        index += 2;
        System.arraycopy(osType, 0, data, index, osTypeLen);
        index += osTypeLen;

        int osVersionLen = osVersion.length;
        Util.int16_to_buf(data, index, osVersionLen);
        index += 2;
        System.arraycopy(osVersion, 0, data, index, osVersionLen);
        index += osVersionLen;

        Util.int16_to_buf(data, index, netWorkType);
        index += 2;

        int simNameLen = simName.length;
        Util.int16_to_buf(data, index, simNameLen);
        index += 2;
        System.arraycopy(simName, 0, data, index, simNameLen);
        index += simNameLen;

        int var5Len = var5.length;
        Util.int16_to_buf(data, index, var5Len);
        index += 2;
        System.arraycopy(var5, 0, data, index, var5Len);
        index += var5Len;

        int apnNameLen = apnName.length;
        Util.int16_to_buf(data, index, apnNameLen);
        index += 2;
        System.arraycopy(apnName, 0, data, index, apnNameLen);

        return this.getBufData(data);
    }

}
